package com.czk.grouptask;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.task.Task;

/**
 * 拾取组中的任务
 * @Author ChenZhangKun
 * @Date 2020/9/15 13:49
 */
public class PickUpTask {
    public static void main(String[] args) {
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // 拿到任务
        TaskService taskService = processEngine.getTaskService();
        // 查询任务
        String key="czk";
        String candidate_user="李洪赭";
        Task task = taskService.createTaskQuery()
                .processDefinitionKey(key)
                .taskCandidateUser(candidate_user)
                .singleResult();
        if (task!=null){
            // 拾取任务
            taskService.claim(task.getId(),candidate_user);
            System.out.println("拾取任务完毕");
        }else {
            System.out.println("没有查询到任务");
        }
    }
}
